/**
 * Copyright &copy; 2016-2017 <a href="https://www.lczyfz.com">联创智云</a> All rights reserved.
 */
package com.lczyfz.campusinfo.modules.campusinfohelp.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lczyfz.campusinfo.common.config.Global;
import com.lczyfz.campusinfo.common.persistence.Page;
import com.lczyfz.campusinfo.common.web.BaseController;
import com.lczyfz.campusinfo.common.utils.StringUtils;
import com.lczyfz.campusinfo.modules.campusinfohelp.entity.CampusinfoHelp;
import com.lczyfz.campusinfo.modules.campusinfohelp.service.CampusinfoHelpService;

/**
 * 帮助中心Controller
 * @author zms
 * @version 2018-04-16
 */
@Controller
@RequestMapping(value = "${adminPath}/campusinfohelp/campusinfoHelp")
public class CampusinfoHelpController extends BaseController {

	@Autowired
	private CampusinfoHelpService campusinfoHelpService;
	@ModelAttribute
	public CampusinfoHelp get(@RequestParam(required=false) String id) {
		CampusinfoHelp entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = campusinfoHelpService.get(id);
		}
		if (entity == null){
			entity = new CampusinfoHelp();
		}
		return entity;
	}
	
	@RequiresPermissions("campusinfohelp:campusinfoHelp:view")
	@RequestMapping(value = {"list", ""})
	public String list(CampusinfoHelp campusinfoHelp, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<CampusinfoHelp> page = campusinfoHelpService.findPage(new Page<CampusinfoHelp>(request, response), campusinfoHelp);
		model.addAttribute("page", page);
		return "modules/campusinfohelp/campusinfoHelpList";
	}

	@RequiresPermissions("campusinfohelp:campusinfoHelp:view")
	@RequestMapping(value = "form")
	public String form(CampusinfoHelp campusinfoHelp, Model model) {
		model.addAttribute("campusinfoHelp", campusinfoHelp);
		return "modules/campusinfohelp/campusinfoHelpForm";
	}

	@RequiresPermissions("campusinfohelp:campusinfoHelp:edit")
	@RequestMapping(value = "save")
	public String save(CampusinfoHelp campusinfoHelp, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, campusinfoHelp)){
			return form(campusinfoHelp, model);
		}
		campusinfoHelpService.save(campusinfoHelp);
		addMessage(redirectAttributes, "保存帮助中心成功");
		return "redirect:"+Global.getAdminPath()+"/campusinfohelp/campusinfoHelp/?repage";
	}
	
	@RequiresPermissions("campusinfohelp:campusinfoHelp:edit")
	@RequestMapping(value = "delete")
	public String delete(CampusinfoHelp campusinfoHelp, RedirectAttributes redirectAttributes) {
		campusinfoHelpService.delete(campusinfoHelp);
		addMessage(redirectAttributes, "删除帮助中心成功");
		return "redirect:"+Global.getAdminPath()+"/campusinfohelp/campusinfoHelp/?repage";
	}
}